home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
ObjFloat.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-05
|
971b
|
60 lines
#ifdef __GNUG__
#pragma implementation
#endif
#include "ObjFloat.h"
#include "Class.h"
#include "String.h"
NewMetaImpl(ObjFloat,Object, (T(val)));
//---- a float object ----------------------------------------------------------
// hashing idea stolen from OOPS
static union {
unsigned long aslong[2];
double asdouble;
} hashunion;
u_long ObjFloat::Hash()
{
hashunion.asdouble= val;
return hashunion.aslong[0] ^ hashunion.aslong[1];
}
bool ObjFloat::IsEqual(Object* op)
{
return (bool) (op->IsKindOf(ObjFloat) && val == ((ObjFloat*)op)->val);
}
int ObjFloat::Compare(Object* op)
{
double t = val - Guard(op, ObjFloat)->val;
if (t < 0)
return -1;
if (t > 0)
return 1;
return 0;
}
char* ObjFloat::AsString()
{
return form("%g", val);
}
OStream& ObjFloat::PrintOn(OStream &s)
{
Object::PrintOn(s);
return s << val SP;
}
IStream& ObjFloat::ReadFrom(IStream &s)
{
Object::ReadFrom(s);
return s >> val;
}